﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Scrabble.Model.Events
{
    internal abstract class GameEvent : IGameEvent
    {
        protected GameEvent(IPlayer player, int score, IEnumerable<Tile> tiles)
        {
            Player = player;
            Score = score;
            DurationOfPlay = TimeSpan.Zero;
            MovedTiles = (tiles ?? Enumerable.Empty<Tile>()).ToArray();
        }

        public IPlayer Player
        {
            get;
            private set;
        }

        public int Score
        {
            get;
            private set;
        }

        public TimeSpan DurationOfPlay
        {
            get;
            set;
        }

        public string Description
        {
            get; protected set;
        }

        public Tile[] MovedTiles
        {
            get; private set;
        }

        public virtual string ToNotation()
        {
            return string.Empty;
        }

        public RecordOfPlay ToRecordOfPlay()
        {
            return new RecordOfPlay
                    {
                        Type = TypeOfAction,
                        DurationOfPlay = DurationOfPlay,
                        Notation = ToNotation()
                    };
        }

        protected abstract string TypeOfAction { get; }
    }
}